Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decode batch message #48

Merged
merged 3 commits into from
May 14, 2019
Merged

decode batch message #48

merged 3 commits into from
May 14, 2019

Conversation

LvBay
Copy link

@LvBay LvBay commented May 13, 2019

Provides a method for parsing the payload generated by the producer using the batch produce option.

Copy link
Owner

@wolfstudy wolfstudy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice job, left a little comments, can you fix it?

core/msg/message.go Outdated Show resolved Hide resolved

func DecodeBatchMessage(msg *Message)([]*SingleMessage, error){
num := msg.Meta.GetNumMessagesInBatch()
if num==0{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if num==0{
if num == 0 {

func DecodeBatchMessage(msg *Message)([]*SingleMessage, error){
num := msg.Meta.GetNumMessagesInBatch()
if num==0{
return nil,errors.New("num_message_in_batch is nil or 0")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return nil,errors.New("num_message_in_batch is nil or 0")
return nil, errors.New("num_message_in_batch is nil or 0")

if num==0{
return nil,errors.New("num_message_in_batch is nil or 0")
}
return DecodeBatchPayload(msg.Payload,num)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return DecodeBatchPayload(msg.Payload,num)
return DecodeBatchPayload(msg.Payload, num)

)

func TestDecodeBatchPayload(t *testing.T){
payload := []byte{0,0,0,2,24,12,104,101,108,108,111,45,112,117,108,115,97,114} // hello-pulsar
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
payload := []byte{0,0,0,2,24,12,104,101,108,108,111,45,112,117,108,115,97,114} // hello-pulsar
payload := []byte{0, 0, 0, 2, 24, 12, 104, 101, 108, 108, 111, 45, 112, 117, 108, 115, 97, 114} // hello-pulsar

func TestDecodeBatchPayload(t *testing.T){
payload := []byte{0,0,0,2,24,12,104,101,108,108,111,45,112,117,108,115,97,114} // hello-pulsar
list,err := DecodeBatchPayload(payload,1)
if err!=nil{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if err!=nil{
if err != nil {

if err!=nil{
t.Fatal(err)
}
if get,want := len(list),1;get!=want{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if get,want := len(list),1;get!=want{
if get, want := len(list), 1; get!=want {

t.Fatal(err)
}
if get,want := len(list),1;get!=want{
t.Errorf("want %v, but get %v",get,want)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
t.Errorf("want %v, but get %v",get,want)
t.Errorf("want %v, but get %v", get, want)

}

m := list[0]
if get,want := string(m.SinglePayload), "hello-pulsar";get!=want{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if get,want := string(m.SinglePayload), "hello-pulsar";get!=want{
if get, want := string(m.SinglePayload), "hello-pulsar"; get != want {


m := list[0]
if get,want := string(m.SinglePayload), "hello-pulsar";get!=want{
t.Errorf("want %v, but get %v",get,want)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
t.Errorf("want %v, but get %v",get,want)
t.Errorf("want %v, but get %v",get, want)

@wolfstudy wolfstudy assigned wolfstudy and LvBay and unassigned wolfstudy May 13, 2019
@wolfstudy wolfstudy requested review from cch123 and sijie May 13, 2019 14:23
SinglePayload []byte
}

func DecodeBatchMessage(msg *Message)([]*SingleMessage, error){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported function should have comment

@LvBay
Copy link
Author

LvBay commented May 13, 2019

nice job, left a little comments, can you fix it?

Sorry for so many problems of format, i have fix them.

And thank you very much for pointing out every mistake.

@wolfstudy @cch123

@wolfstudy wolfstudy merged commit 8f5aa74 into wolfstudy:master May 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants